package kz.kstu.shop.app.delegate.impl;

import kz.kstu.shop.app.delegate.api.SyncDelegate;
import kz.kstu.shop.app.util.locator.ServiceLocator;
import kz.kstu.shop.app.util.locator.factory.ServiceLocatorFactory;
import kz.kstu.shop.business.entity.Synchronizable;
import kz.kstu.shop.facade.ejb.api.SyncFacade;

import java.util.List;

/**
 * @author Filipp_Stankevich
 *         created: 8/9/11 6:08 PM
 */
public class SyncDelegateImpl implements SyncDelegate {
    @Override
    public <T extends Synchronizable> List<Synchronizable> findForSyncOnServer(Class<T> classForSync, Long changeDate) {
        return getSyncFacade(true).findForSync(classForSync, changeDate);
    }

    @Override
    public void saveSycnhronazableOffline(List<Synchronizable> entities) {
        getSyncFacade(false).saveSycnhronazable(entities);
    }

    private SyncFacade getSyncFacade(boolean isOnline) {
        ServiceLocator serviceLocator = ServiceLocatorFactory.getServiceLocator(isOnline);
        return serviceLocator.getService(SyncFacade.SERVICE_NAME, SyncFacade.class);
    }
}
